<?php
/*
 * 产品评论数据库安装文件
 *
 * @author		Arthur(ArthurXF@gmail.com)
 * @copyright	(c) 2006 by bizeway.com
 * @version		$Id$
 * modified		2009-1-3
 */
include_once(dirname(__FILE__).'/config/config.inc.php');
include_once(dirname(__FILE__).'/class/comments.class.php');

$objWebInit = new comments();
//数据库连接参数
$objWebInit->setDBG($arrGPdoDB);
//smarty参数
$objWebInit->arrGSmarty = $arrGSmarty;
$objWebInit->db();

if(empty($charset)) $charset = str_replace('-', '', $arrGWeb['charset']);
if(empty($charset)) $extend = $objWebInit->db->getAttribute(PDO::ATTR_SERVER_VERSION) > '4.1' ? " DEFAULT CHARSET={$charset} " : "";

//写入频道数组
if(empty($strWEB_ROOT_pre)) $strWEB_ROOT_pre = $arrGWeb['WEB_ROOT_pre'];
if(empty($strWEBADMIN_ROOT)) $strWEBADMIN_ROOT = $arrGWeb['WEBADMIN_ROOT'];
unset($arrGWeb);
$strFilename = __WEB_ROOT.'/data/webconfig.inc.php';
include($strFilename);
$arrGMeta['comments']['name'] = '产品评论';
$arrGMeta['comments']['admin'] = array(
									array(
										  'href'=>'../comments/admin/index.php',
										  'name'=>'产品评论管理',),
									);
$arrGMeta['comments']['meta'] = array(
									  'Title' => $arrGMeta['comments']['name'],
									  'Description' => $arrGMeta['comments']['name'],
									  'Keywords' => $arrGMeta['comments']['name'],
									);
$somecontent = '<?php' . "\n" . '$arrGWeb = ' . var_export( $arrGWeb, true ) . ';' . "\n" . '$arrGMeta = ' . var_export( $arrGMeta, true ) . ';' . "\n" . '?>';

// 首先我们要确定文件存在并且可写。
if (is_writable($strFilename)) {

	if (!$handle = fopen($strFilename, 'w')) {
		 check::AlertExit("错误：不能打开文件 $strFilename !",-1);
	}

	// 将$somecontent写入到我们打开的文件中。
	if (fwrite($handle, $somecontent) === FALSE) {
		check::AlertExit("错误：不能写入到文件 $strFilename !",-1);
	}
	fclose($handle);
} else {
	check::AlertExit("错误：文件 $strFilename 不可写!",-1);
}

//sql语句
$sql[] = "CREATE TABLE IF NOT EXISTS `".$arrGPdoDB['db_tablepre']."comments` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `type_id` tinyint(3) unsigned DEFAULT NULL,
  `pid` int(10) unsigned DEFAULT NULL COMMENT '产品id',
  `user_id` int(10) unsigned DEFAULT '0',
  `brand` varchar(30) default NULL COMMENT '产品品牌',
  `model` varchar(30) default NULL COMMENT '产品型号',
  `pname` varchar(30) default NULL COMMENT '产品名称',
  `commentsname` varchar(30) default NULL COMMENT '评论者',
  `title` varchar(30) default NULL COMMENT '评论标题',
  `intro` text default NULL COMMENT '评论内容',
  `user_ip` varchar(30) default NULL,
  `submit_date` datetime DEFAULT '0000-00-00 00:00:00',
  `state` tinyint(1) unsigned DEFAULT 0 COMMENT '处理状态',
  `pass` tinyint(1) DEFAULT '1',
  PRIMARY KEY (`id`),
  KEY `user_id` (`user_id`),
  KEY `pid` (`pid`),
  KEY `type_id` (`type_id`),
  KEY `submit_date` (`submit_date`)
) ENGINE=MyISAM {$extend} COMMENT='产品评论表' ;";


foreach($sql as $val){
	$objWebInit->db->query($val);
}

if(empty($arrModule)){
	check::AlertExit('产品评论系统安装成功',"$strWEB_ROOT_pre$strWEBADMIN_ROOT/");
}
?>